package com.onelap.bls.tc2.util;

import android.os.Handler;
import android.os.Message;

import java.lang.ref.WeakReference;

/**
 * 　　  () 　　　  ()
 * 　　  ( ) 　　　( )
 * 　　  ( ) 　　　( )
 * 　　┏┛┻━━━┛┻┓
 * 　　┃　　　━　　　┃
 * 　　┃　┳┛　┗┳　┃
 * 　　┃　　　┻　　　┃
 * 　　┗━┓　　　┏━┛
 * 　　　　┃　　　┃
 * 　　　　┃　　　┗━━━┓
 * 　　　　┃　　　　　　　┣┓
 * 　　　　┃　　　　　　　┏┛
 * 　　　　┗┓┓┏━┳┓┏┛
 * 　　　　　┃┫┫　┃┫┫
 * 　　　　　┗┻┛　┗┻┛
 * ——————————————————
 * Created by BinglingSu on 2017/10/16.
 */


/*

myHandler.sendMessage(Message.obtain(myHandler, 0, dataBean));

private MyHandler myHandler = new MyHandler(IndexActivity.this);

private static class MyHandler extends HandleUtils<IndexActivity> {
    MyHandler(IndexActivity rootT) {
        super(rootT);
    }

    @Override
    public void handler0Event(IndexActivity object, Message msg) {
        super.handler0Event(object, msg);

    }
}*/
public class HandleUtils<T> extends Handler {

    private WeakReference<T> weakReference;

    public HandleUtils(T rootT) {
        this.weakReference = new WeakReference<T>(rootT);
    }

    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        T object = this.weakReference.get();
        switch (msg.what) {
            case 0:
                handler0Event(object, msg);
                break;
            case 1:
                handler1Event(object, msg);
                break;
            case 2:
                handler2Event(object, msg);
                break;
            case 3:
                handler3Event(object, msg);
                break;
            case 4:
                handler4Event(object, msg);
                break;
            case 5:
                handler5Event(object, msg);
                break;
            case 6:
                handler6Event(object, msg);
                break;
            case 7:
                handler7Event(object, msg);
                break;
            case 8:
                handler8Event(object, msg);
                break;
            case 9:
                handler9Event(object, msg);
                break;
            default:
                handlerEvent(object, msg);
                break;

        }
    }

    public void handler0Event(T object, Message msg) {

    }

    public void handler1Event(T object, Message msg) {

    }

    public void handler2Event(T object, Message msg) {

    }

    public void handler3Event(T object, Message msg) {

    }

    public void handler4Event(T object, Message msg) {

    }

    public void handler5Event(T object, Message msg) {

    }

    public void handler6Event(T object, Message msg) {

    }

    public void handler7Event(T object, Message msg) {

    }

    public void handler8Event(T object, Message msg) {

    }

    public void handler9Event(T object, Message msg) {

    }

    public void handlerEvent(T object, Message msg) {

    }
}

